package com.taotao.service.impl;

import com.taotao.entity.MayiktIntegralInfo;
import com.taotao.dao.MayiktIntegralInfoDao;
import com.taotao.service.MayiktIntegralInfoService;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (MayiktIntegralInfo)表服务实现类
 *
 * @author makejava
 * @since 2022-01-23 21:08:48
 */
@Service("mayiktIntegralInfoService")
public class MayiktIntegralInfoServiceImpl implements MayiktIntegralInfoService {
    @Resource
    private MayiktIntegralInfoDao mayiktIntegralInfoDao;

    @Override
    public ResponseEntity addIntegral(MayiktIntegralInfo integralDto) {
        return null;
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public MayiktIntegralInfo queryById(Integer id) {
        return this.mayiktIntegralInfoDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param mayiktIntegralInfo 筛选条件
     * @param pageRequest        分页对象
     * @return 查询结果
     */
    @Override
    public Page<MayiktIntegralInfo> queryByPage(MayiktIntegralInfo mayiktIntegralInfo, PageRequest pageRequest) {
        long total = this.mayiktIntegralInfoDao.count(mayiktIntegralInfo);
        return new PageImpl<>(this.mayiktIntegralInfoDao.queryAllByLimit(mayiktIntegralInfo, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param mayiktIntegralInfo 实例对象
     * @return 实例对象
     */
    @Override
    public MayiktIntegralInfo insert(MayiktIntegralInfo mayiktIntegralInfo) {
        this.mayiktIntegralInfoDao.insert(mayiktIntegralInfo);
        return mayiktIntegralInfo;
    }

    /**
     * 修改数据
     *
     * @param mayiktIntegralInfo 实例对象
     * @return 实例对象
     */
    @Override
    public MayiktIntegralInfo update(MayiktIntegralInfo mayiktIntegralInfo) {
        this.mayiktIntegralInfoDao.update(mayiktIntegralInfo);
        return this.queryById(mayiktIntegralInfo.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.mayiktIntegralInfoDao.deleteById(id) > 0;
    }
}
